package com.smartbands.wechat.interceptor;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 使用拦截骑拦截请求，验证token
 * @author mtf
 * @create 2021-01-29-10:41
 */
@Component
public class JWTInterceptor implements HandlerInterceptor {
    private static final Logger logger = LoggerFactory.getLogger(JWTInterceptor.class);
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        logger.info("进入拦截器");
        logger.info("request请求地址path[{}] uri[{}]", request.getServletPath(),request.getRequestURI());
//        String token = request.getHeader("token");
//        if(StringUtils.isAllBlank(token)){
//            LOGGER.info("无token认证信息，请登陆");
//            throw new RuntimeException("无token，请重新登录");
//        }
        response.getWriter().write(JSONObject.toJSONString("Login failed"));
        return false;
    }
}
